package com.wenhao.tencent;

import com.wenhao.leetcode.structure.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Wenhao Tong
 * @create 2021-08-22 20:05
 */
public class Main1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param m int整型
     * @param a ListNode类 指向彩带的起点，val表示当前节点的val，next指向下一个节点
     * @return ListNode类一维数组
     */
    public ListNode[] solve (int m, ListNode a) {
        // write code here
        ListNode[] tail = new ListNode[m];
        ListNode[] head = new ListNode[m];
        while (a != null) {
            int index = a.val % m;
            if (head[index] == null) {
                head[index] = a;
                tail[index] = a;
            } else {
                tail[index].next = a;
                tail[index] = a;
            }
            a = a.next;
            a.next = null;
        }
        return head;
    }
}
